package org.xs.object.controller;


import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.xs.object.dao.user.BaseUser;
import org.xs.object.dao.page.PageResquest;
import org.xs.object.service.impl.UserService;
import org.xs.object.utils.R;

import java.util.Map;

@RestController
@RequestMapping("/api/user")
public class UserController {
    UserService userService;
    @Autowired
    public UserController(UserService userService){
        this.userService=userService;
    }

    @PostMapping("/login")
    public R login(@RequestBody BaseUser user) {
        return userService.login(user.getUsername(),user.getPassword());
    }
    @PostMapping("/register")
    public R register(@RequestBody BaseUser user) {
        return userService.register(user.getUsername(),user.getPassword());
    }
    @DeleteMapping("/logout")
    public R logout(HttpServletRequest request) {
        return userService.logout(request);
    }
    @GetMapping("/info")
    public R info(HttpServletRequest request) {
        return userService.info(request);
    }
    @PutMapping("/update")
    public R updata(@RequestBody BaseUser user) {
        return userService.update(user);
    }

    @PostMapping("/updateAvatar")
    public R upload(MultipartFile file){
        return userService.updateAvatar(file);
    }

    @GetMapping("/getAvatar")
    public R getAvatar() {
        return userService.getAvatar();
    }
    @PatchMapping("/updatePassword")
    public R updatePassword(@RequestBody Map<String, String> params) {
        return userService.updatePassword(params);
    }
    @PostMapping("/getUserList")
    public R getUserList(@RequestBody PageResquest pageRequest) {
        return userService.getUserList(pageRequest);
    }

    @DeleteMapping("/userdelete")
    public R userdelete() {
        return userService.userdelete();
    }
}

